jQuery.extend({
	resetPwd: function(userCode,userName){
		if( window.confirm('确定要重置'+ userName +'的密码？') ){
			jQuery.jsonPost({
				url:_ctx +"/uums/resetPwd.do",
				data:{userCode:userCode},
				jsonStatusSuccessCall:function(msg,data){
					alert(msg);
			    },
			    jsonStatusFailCall:function(msg){
					   alert(msg);
			    }
			});
		}
		
	},
	/**
	 * 批量停用
	 */
	batchDelete:function(){
		var codes = $("input[name='code'][disabled!=disabled]:checked");//jquery语法，选择页面中所有input表单中name=ids且被选中的值
		if(codes.length == 0){
			alert('至少选择一条未停用的用户记录!');
			return;
		}	
		
		var codesVal = "";
		for(var i=0;i<codes.length;i++){
			codesVal += $(codes[i]).val() +",";
		}
		codesVal = codesVal.substring(0,codesVal.length - 1);
		
		if( window.confirm('确定要停用选中的'+ codes.length +'条记录?') ){
			var loader = $("a[data-loader='batchDelete']");
			var loaderVal = loader.html();
			jQuery.jsonPost({
				   url : _ctx + "/uums/batch_delete_user_info.do",
				   data: {"codes": codesVal},
			       jsonStatusSuccessCall:function(msg){
					  alert(msg);
					  document.location.reload();
				    },
				    jsonStatusFailCall:function(msg){
						   alert(msg);
				    }
			 });
		}
	},
	getJobsForDep: function(){
		var depCode = $("#depCode").val();
		if($.trim(depCode)==''){
			zNodes="";
			loadJobTree();
			return;
		};
		jQuery.jsonPost({
			url:_ctx +"/uums/get_jobs_for_dep.do",
			data:"depCode="+depCode,
			jsonStatusSuccessCall:function(msg,data){
				zNodes = eval(data);
				loadJobTree();
		    },
		    jsonStatusFailCall:function(msg){
				   alert(msg);
		    },
			error:function(msg, textStatus,c){
			  alert([msg, textStatus,c]);
			}
		});
	},
	getUserCheckedJobs: function(){
		var depCode = $("#depCode").val();
		var userCode = $("#userCode").val();
		if($.trim(depCode)==''|| userCode==''){
			zNodes="";
			loadUserJobTree();
			return;
		};
		jQuery.jsonPost({
			url:_ctx +"/uums/get_user_checked_jobs.do",
			data:{depCode:depCode,userCode:userCode},
			jsonStatusSuccessCall:function(msg,data){
				zNodes = eval(data);
				loadUserJobTree();
			},
			jsonStatusFailCall:function(msg){
				alert(msg);
			},
			error:function(msg, textStatus,c){
				alert([msg, textStatus,c]);
			}
		});
	},
	delete_user: function(confirm_msg,url){
		if(window.confirm(confirm_msg)){
			jQuery.jsonGet({
				url:url,
				jsonStatusSuccessCall:function(msg,data){
					   alert(msg);
					   jQuery.refresh();//刷新界面
			    },
			    jsonStatusFailCall:function(msg){
					  alert(msg); 
			    }
			});
		}
	},
	
	/**
	 * 显示复选框中选择的岗位列表
	 */
	showSel: function(checkbox){
		var $checkbox = $(checkbox);
		var id = $checkbox.val();
		var name=$checkbox.attr("relname");//?获取姓名
		var selDiv = $("#selectedDiv");
		
		//"<input type='radio' name='selUser' id='"+id+"' />"+
		var cont = "<label for='"+id+"'>"+name+"</label>"+
			  	   "<img id='img"+id+"' src='"+_ctx+"/images/delete.gif' title='停用岗位'  height='9' width='9' onclick='javascript:$.delSel(\""+id+"\");'/>";
		if($checkbox.is(":checked")){
			selDiv.append(cont);
		}else{
	    	$("input#"+id).remove();
	    	$("label[for='"+id+"']").remove();
	    	$("img#img"+id).remove();
		}
    },
    /**
     * 停用所选岗位，并且设置对应checkbox选中状态
     */
    delSel: function(id){
    	var chkBoxs = $("input[name='ids']");
    	for(var i=0; i<chkBoxs.length; i++){
    		if(chkBoxs[i].value == id){
    			$(chkBoxs[i]).attr("checked",false);
    			break;
    		}
    	}
    	
    	$("input#"+id).remove();
    	$("label[for='"+id+"']").remove();
    	$("img#img"+id).remove();
    },
    /**
     * 返回设置结果
     */
    rtn: function(){
    	var result = new Object();
    	jobCode="";
    	var allRadio = $("input[name='ids']");
    	for(var i=0; i<allRadio.length; i++){
    		jobCode += $(allRadio[i]).val()+",";
    	}
    	jobCode = jobCode.substring(0, jobCode.length-1);
    	result.jobCode = jobCode;
		window.returnValue = result;
		window.close();
    },
		
    /**
    * 取消后直接关闭窗口
    */
    console: function(){
    	window.close();
    }
	
});
